package com.gitee.zw.irmp.common;

import org.springframework.http.HttpInputMessage;
import org.springframework.http.HttpOutputMessage;
import org.springframework.http.MediaType;
import org.springframework.http.converter.ByteArrayHttpMessageConverter;
import org.springframework.http.converter.GenericHttpMessageConverter;
import org.springframework.http.converter.HttpMessageNotReadableException;
import org.springframework.http.converter.HttpMessageNotWritableException;

import java.io.IOException;
import java.lang.reflect.Type;
import java.util.List;


public class ByteArrayListHttpMessageConverter implements GenericHttpMessageConverter<List<byte[]>> {
    ByteArrayHttpMessageConverter converter = new ByteArrayHttpMessageConverter();

    @Override
    public boolean canRead(Type type, Class<?> contextClass, MediaType mediaType) {
        return converter.canRead(byte[].class, mediaType);
    }

    @Override
    public List<byte[]> read(Type type, Class<?> contextClass, HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException {
        return List.of(converter.read(byte[].class, inputMessage));
    }

    @Override
    public boolean canWrite(Type type, Class<?> clazz, MediaType mediaType) {
        return false;
    }

    @Override
    public void write(List<byte[]> bytes, Type type, MediaType contentType, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException {

    }

    @Override
    public boolean canRead(Class<?> clazz, MediaType mediaType) {
        return converter.canRead(byte[].class, mediaType);
    }

    @Override
    public boolean canWrite(Class<?> clazz, MediaType mediaType) {
        return false;
    }

    @Override
    public List<MediaType> getSupportedMediaTypes() {
        return converter.getSupportedMediaTypes();
    }

    @Override
    public List<byte[]> read(Class<? extends List<byte[]>> clazz, HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException {
        return List.of(converter.read(byte[].class, inputMessage));
    }

    @Override
    public void write(List<byte[]> bytes, MediaType contentType, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException {

    }
}
